package com.myh.cc.coom.ranking.viewmodel

import android.support.v7.widget.LinearLayoutManager
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.myh.cc.base.BaseModel
import com.myh.cc.coom.ranking.adapter.RankingDetailsAdapter
import com.myh.cc.coom.ranking.bean.RankingDetailsBean
import com.myh.cc.coom.ranking.net.RankingNetControl
import com.myh.cc.databinding.ActivityRaningDetailsBinding
import com.myh.cc.util.ConstantUtil

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/18.   ：
 */
class RankingDetailsModel: BaseModel<ActivityRaningDetailsBinding,RankingNetControl>(){


    override fun onBeforeRequest(tag: Int) {

    }

    override fun onSuccess(data: Any, tag: Int) {
        initRecycleView(data as RankingDetailsBean)
    }

    override fun onError(errorMag: String, tag: Int) {

    }


    fun getRankingDetails(topId: String){

        val map = HashMap<String,String>()

        map.put("format","json")
        map.put("g_tk","5381")
        map.put("uin","0")
        map.put("needNewCode","1")
        map.put("tpl","3")
        map.put("page","detail")
        map.put("type","top")
        map.put("topid",topId)
        mControl.getRankingDetails(this,"",map,ConstantUtil.requestTagOne)

    }

    fun initRecycleView(bean: RankingDetailsBean){

        val picUrl = "https://y.gtimg.cn/music/photo_new/T001R300x300M000"+bean.topinfo.pic_album+".jpg?max_age=2592000"

        Glide.with(getContext()).load(picUrl).into(mBinder.rdIvImg)

        mBinder.rdTvName.text = bean.topinfo.ListName

        mBinder.rdTvDesc.text = "歌曲共"+bean.total_song_num+"首"

        mBinder.rdDetialsTv.layoutManager = LinearLayoutManager(getContext(), LinearLayout.VERTICAL,false)
        mBinder.rdDetialsTv.adapter = RankingDetailsAdapter(bean,getContext())

    }
}